package com.zzh.interview.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author 张 志 豪
 * @version 1.0
 * RedissonConfig配置客户端
 */
@Component
@ConfigurationProperties(prefix = "spring.redis")
@Data
public class RedissonConfig {

    private String host;
    private String port;
    private String password;

    @Bean
    public RedissonClient redissonClient(){
        //创建配置
        Config config = new Config();
        String redisAddress = String.format("redis://%s:%s",host,port);
        //创建实例（单机）useClusterServers（集群）（3库）
        config.useSingleServer().setAddress(redisAddress).setPassword(password).setDatabase(3);
        RedissonClient redissonClient = Redisson.create(config);
        return redissonClient;
    }
}
